from pyglet.window import mouse

from main import main

class Cursor:
    """Executes input related functions.
    
    The function that gets executed depends on the trigger input and the
    previously executed function.
    """
    def __init__(self):
        """Doesn't do much.
        
        You'll at least have to put an element in self.followup,
        and set self.last to it.
        
        e.g: self.followup[func1] = {mouse button1: func2, mb2: func3}
        """
        self.followup = {} #{last action: {mouse button: action}}
        self.last = None
        
        main.window.on_mouse_press = self.on_mouse_press
    
    def on_mouse_press(self, x, y, button, modifiers):
        if button in self.followup[self.last]:
            action = self.followup[self.last][button]
            action()
            self.last = action

if __name__ == '__main__': #Just an example, really
    def nothing():
        print "actually something"
    
    def frothin():
        print "yeaahrite"
    
    cursor = Cursor()
    cursor.followup[self.nothing] = {mouse.LEFT: self.nothing,
                                     mouse.RIGHT: self.frothin}
    cursor.followup[self.frothin] = {mouse.LEFT: self.nothing,
                                     mouse.RIGHT: self.nothing}